Potential energy is the energy an object possesses depending on its position. A common example of potential energy uses objects on the Earth's surface. Since energy has units of work, consider the work done by gravity over some height h.
Then potential energy due to gravity has the definition
Gravitational potential energy exists between objects in general, not just those in Earth's gravitational field. Consider the work required to move an object of mass m from "infinitely far away" to some distance r from another object of mass M. Since potential energy depends on position, define potential energy at "infinitely far away" to be 0. Since the definition of gravitational force has the value of the radius in the denominator, if the radius approaches infinity, then the force approaches 0. The work done is therefore